package com.fantasybaby.user.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fantasybaby.common.bean.Account;
import com.fantasybaby.dao.IAccountDao;
import com.fantasybaby.page.Pager;
import com.fantasybaby.page.SystemContext;
import com.fantasybaby.user.service.IAccountService;
@Service("accountMybatisService")
public class AccountMybatisService implements IAccountService{
	@Autowired
	private IAccountDao accountDao;
	@Override
	public boolean addAccount(Account account) {
		boolean flag = false;
		try {
			accountDao.add(account);
			flag =true;
		} catch (Exception e) {
			throw e;
		}
		return flag;
	}
	@Override
	public boolean updateAccount(Account account) {
		boolean flag = false;
		try {
			accountDao.update(account);
			flag =true;
		} catch (Exception e) {
			throw e;
		}
		return flag;
	}
	@Override
	public boolean deleteAccount(Account account) {
		boolean flag = false;
		try {
			accountDao.delete(account.getId());
			flag =true;
		} catch (Exception e) {
			throw e;
		}
		return flag;
	}
	@Override
	public Account loadAccount(int id) {
		return accountDao.load(id);
	}
	@Override
	public Pager<Account> findPager(Map<String, Object> map) {
		List<Account> findPager = accountDao.findPager(map);
		int count = accountDao.findPageCount();
		Pager<Account> pager = new Pager<Account>();
		pager.setDatas(findPager);
		pager.setTotalRecord(count, SystemContext.getPageSize());
		return pager;
	}
	@Override
	public boolean deleteTrans() {
		/*Account ac = null;
		accountDao.delete(5);
		Account ac2 = accountDao.load(6);
		ac2.setName("更新名称2");
		ac.getName();
		accountDao.update(ac2);*/
		return false;
	}
}
